package com.ruoyi.energy.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.TcIn;
import com.ruoyi.energy.domain.vo.TcInWXVO;
import com.ruoyi.energy.service.ITcInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 进场回调Controller
 *
 * @author cjie
 * @date 2021-11-30
 */
@Api(tags = " 进场回调")
@RestController
@RequestMapping("/tcIn")
public class TcInController extends BaseController {
    @Autowired
    private ITcInService tcInService;

    /**
     * 查询进场回调列表
     */
    @ApiOperation(value="查询进场回调列表", notes="查询进场回调列表")
    @PreAuthorize(hasPermi = "energy:tcIn:list")
    @GetMapping("/list")
    public TableDataInfo list(TcIn tcIn) {
        startPage();
        List<TcIn> list = tcInService.selectTcInList(tcIn);
        return getDataTable(list);
    }

    /**
     * 微信查询进场回调列表
     */
    @ApiOperation(value="微信查询进场回调列表", notes="微信查询进场回调列表")
    @PreAuthorize(hasPermi = "energy:tcIn:list")
    @GetMapping("/wx/list")
    public TableDataInfo wxList(TcInWXVO tcIn) {
        startPage();
        TcIn search = BeanUtil.toBean(tcIn,TcIn.class);
        List<TcIn> tcIns = tcInService.selectTcInList(search);
        TableDataInfo tableData = getDataTable(tcIns);
        List<TcInWXVO> results = new ArrayList<>(tcIns.size());
        for(TcIn tcin:tcIns){
            results.add(BeanUtil.toBean(tcin,TcInWXVO.class));
        }
        tableData.setRows(results);
        return tableData;
    }

    /**
     * 导出进场回调列表
     */
    @ApiOperation(value="导出进场回调列表", notes="导出进场回调列表")
    @PreAuthorize(hasPermi = "energy:tcIn:export")
    @Log(title = "进场回调", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcIn tcIn) throws IOException {
        List<TcIn> list = tcInService.selectTcInList(tcIn);
        ExcelUtil<TcIn> util = new ExcelUtil<TcIn>(TcIn.class);
        util.exportExcel(response, list, "进场回调数据");
    }
    /**
     * 获取进场回调详细信息
     */
    @ApiOperation(value="获取进场回调详细信息", notes="获取进场回调详细信息")
    @PreAuthorize(hasPermi = "energy:tcIn:query")
    @GetMapping(value = "/{parkId}")
    public AjaxResult getInfo(@PathVariable("parkId") String parkId) {
        return AjaxResult.success(tcInService.selectTcInById(parkId));
    }

    /**
     * 新增进场回调
     */
    @ApiOperation(value="新增进场回调", notes="新增进场回调")
    @PreAuthorize(hasPermi = "energy:tcIn:add")
    @Log(title = "进场回调", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcIn tcIn) {
        return toAjax(tcInService.insertTcIn(tcIn));
    }

    /**
     * 修改进场回调
     */
    @ApiOperation(value="修改进场回调", notes="修改进场回调")
    @PreAuthorize(hasPermi = "energy:tcIn:edit")
    @Log(title = "进场回调", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcIn tcIn) {
        return toAjax(tcInService.updateTcIn(tcIn));
    }

    /**
     * 删除进场回调
     */
    @ApiOperation(value="删除进场回调", notes="删除进场回调")
    @ApiImplicitParam(name = "ids", value = "进场回调ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:tcIn:remove")
    @Log(title = "进场回调", businessType = BusinessType.DELETE)
    @DeleteMapping("/{parkIds}")
    public AjaxResult remove(@PathVariable String[] parkIds) {
        return toAjax(tcInService.deleteTcInByIds(parkIds));
    }
}
